package com.yingsheng.bi.hks.service.serviceinfo;

import com.yingsheng.bi.hks.basic.PUser;
import com.yingsheng.bi.hks.basic.utils.Subject;
import com.yingsheng.bi.hks.bo.ServiceInfoBo;
import com.yingsheng.bi.hks.bo.ServiceOrdersBo;
import com.yingsheng.bi.hks.dto.serviceinfo.*;
import com.yingsheng.bi.hks.mapping.ServiceInfoMgmtMappings;
import com.yingsheng.bi.hks.repository.dao.po.ServiceInfo;
import com.yingsheng.bi.hks.repository.dao.po.ServiceOrders;
import com.yingsheng.bi.hks.repository.dao.service.ServiceInfoDaoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import java.util.List;

@Slf4j
@Service
public class ServiceInfoMgmtService {

    @Autowired
    private ServiceInfoDaoService serviceInfoDaoService;

    /**
     * 收件信息新增
     *
     * @param req
     * @return
     */
    public ServiceInfoAddRes add(ServiceInfoAddReq req) {
        ServiceInfo serviceInfo = ServiceInfoMgmtMappings.INSTANCE.addReq2po(req);
        serviceInfoDaoService.insert(serviceInfo);
        return new ServiceInfoAddRes();
    }

    public ServiceInfoModRes mod(ServiceInfoModReq req) {
        ServiceInfo serviceInfo = ServiceInfoMgmtMappings.INSTANCE.addReq2po(req);
        serviceInfoDaoService.updateById(serviceInfo);
        return new ServiceInfoModRes();
    }

    public ServiceInfoQryRes qry(ServiceInfoQryReq req) {
        List<ServiceInfo> list = serviceInfoDaoService.query(req);
        List<ServiceInfoBo> serviceInfoBoList = ServiceInfoMgmtMappings.INSTANCE.serviceInfoList2boList(list);
        ServiceInfoQryRes res = new ServiceInfoQryRes();
        res.setServiceInfoBos(serviceInfoBoList);
        return res;
    }

    public ServiceInfoDelRes del(ServiceInfoDelReq req) {
        serviceInfoDaoService.del(req.getId());
        ServiceInfoDelRes res = new ServiceInfoDelRes();
        return res;
    }

    public ServerOrderListQryRes serverOrderListQry(ServerOrderListQryReq req) {
        PUser user = Subject.get();
        ServiceOrders serviceOrder = new ServiceOrders();
        serviceOrder.setUserId(user.getId());
        serviceOrder.setState(req.getOrderState());
        List<ServiceOrders> serviceOrdersList = serviceInfoDaoService.serverOrderListQry(serviceOrder);
        List<ServiceOrdersBo> serviceOrdersBos = ServiceInfoMgmtMappings.INSTANCE.serviceOrderList2boList(serviceOrdersList);
        ServerOrderListQryRes res = new ServerOrderListQryRes();
        res.setServiceOrdersBos(serviceOrdersBos);
        return res;
    }

    public ServerOrderDetailQryRes serverOrderDetailQry(ServerOrderDetailQryReq req) {
        //todo yyk 差详情
        return null;
    }
}
